home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Comunicatii / htttrack / httrack-3.32-2.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
C/C++ Source or Header  |  2004-01-24  |  104KB  |  2,866 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. #include "htsbase.h"
  12.  
  13. // Ras
  14. #if USE_RAS 
  15. #include "RasLoad.h"
  16. #endif
  17.  
  18. #include <afxdisp.h>
  19. #include "ras.h"
  20.  
  21. //#include "ShellDoc.h"
  22. //#include "ShellView.h"
  23.  
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. // PATCH-->
  31. // PATCH-->
  32. #include "about.h"
  33. #include "infoend.h"
  34.  
  35. // flag de termination
  36. int termine=0;
  37. int termine_requested=0;
  38. int shell_terminated=0;
  39. int soft_term_requested=0;
  40. FILE* fp_debug=NULL;
  41.  
  42. #include "stdafx.h"
  43. #include "Shell.h"
  44. #include "process.h"
  45. //#include "ShellDoc.h"
  46. //#include "ShellView.h"
  47. //#include "essai.h"
  48. //#include "get.h"
  49. //#include "parameter.h"
  50. extern "C" {
  51.   #include "HTTrackInterface.h"
  52.   #include "htssystem.h"
  53. }
  54. #include "Wid1.h"
  55. #include "trans.h"
  56. #include "InfoUrl.h"
  57. //#include "option.h"
  58. //#include "filter.h"
  59. //#include "wizard.h"
  60. //
  61. #include "maintab.h"
  62. //
  63. #include "MemRegister.h"
  64.  
  65. // LANG
  66. #include "newlang.h"
  67.  
  68.  
  69. // PATCH-->
  70. //#include "wizard2.h"
  71. //#include "WizLinks.h"
  72.  
  73. #include "inprogress.h"
  74.  
  75. #include "SYS\TIMEB.H"
  76.  
  77. // htswrap_add
  78. extern "C" {
  79.   #include "htswrap.h"
  80. };
  81.  
  82. // --- --- --- --- Options --- --- --- ---
  83.  
  84. #define MAX_LEN_INPROGRESS 32
  85.  
  86. // lancement en multithread du shell ET de gethostbyname
  87. #define SHELL_MULTITHREAD 1
  88. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  89. // --- --- --- --- Options --- --- --- ---
  90. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  91. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  92. int HTTRACK_result=0;
  93. //
  94. CInfoUrl* _Cinprogress_inst=NULL;
  95.  
  96. extern HICON httrack_icon;
  97.  
  98. /* Main splitter frame */
  99. #include "DialogContainer.h"
  100. #include "splitter.h"
  101. extern CSplitterFrame* this_CSplitterFrame;
  102.  
  103. /* Main WizTab frame */
  104. #include "WizTab.h"
  105. extern CWizTab* this_CWizTab;
  106. /* Argh - pas de domodal dans des autres threads ?!?! */
  107. char WIZ_question[1000];
  108. char WIZ_reponse[1000];
  109.  
  110.  
  111. // Fonctionnement des THREADS:
  112. //
  113. // principal ---> robot & refresh data (thread 1)
  114. //           ---> refresh graphique    (thread 2)
  115. //           GO!> boucle gestion domodal() et boutons
  116. // arrΩt: principal demande l'arrΩt (termine_requested)
  117. //        thread1 active termine et que thread2 ait fini de refresher
  118. //        thread2 se termine
  119. //        thread1 retourne 0 α hts_loop
  120. //        le robot termine
  121. //        le thread1 active termine, termine le formulaire et se termine
  122. //        principal ayant quittΘ le formulaire affiche le message de fin
  123.  
  124.  
  125. // htslib.c
  126. extern "C" {
  127.   HTSEXT_API void qsec2str(char *st,TStamp t);
  128. }
  129.  
  130. // construction index gΘnΘral
  131. // void Build_TopIndex();
  132.  
  133. void compute_options() ;
  134. static void StripControls(char * chaine);
  135. void lance(void);
  136. int check_continue(char* pathlog);
  137. int inprogress_refresh();
  138. //int inprogress_refresh_scan();
  139. void Write_profile(CString path,int load_path);
  140. void Read_profile(CString path,int load_path);
  141.  
  142.  
  143. // dΘja fait mais bon
  144. #define HTS_WIN 1
  145.  
  146. extern "C" {
  147.   #include "htscore.h"
  148. }
  149.  
  150. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  151.  
  152. CShellOptions* ShellOptions;
  153.  
  154.  
  155. // Fichier tempo
  156. FILE* tmpf=NULL;
  157. MemRegister tmpm;
  158.  
  159. CNewProj* dialog0=NULL;
  160. Wid1* dialog1=NULL;
  161. Ctrans* dialog2=NULL;
  162. //Coption dialog3;
  163. //Cfilter diafiltre;
  164. /*
  165. wizard diawiz;
  166. wizard2 diawiz2;
  167. WizLinks diawiz3;
  168. */
  169. //
  170. CMainTab* maintab=NULL;
  171. CShellApp* CShellApp_app=NULL;
  172.  
  173. #include "infoend.h"
  174. extern Cinfoend* this_Cinfoend;
  175.  
  176.  
  177. // PATCH-->
  178. Cinprogress* inprogress=NULL;
  179.  
  180. // nbre de slides
  181. t_StatsBuffer StatsBuffer[NStatsBuffer];
  182. void* StatsBufferback=NULL;
  183. int StatsBufferback_max=0;
  184. InpInfo SInfo;
  185.  
  186. #if USE_RAS
  187. // Chargement des librairies RAS
  188. CDynamicRAS* LibRas=NULL;
  189. int LibRasUse=0;
  190. //
  191. int connected=0;
  192. int disconnect=0;
  193. int shutdown_pc=0;
  194. HRASCONN conn = NULL;
  195. int has_started=0;
  196. char connected_err[1000]="";
  197. #endif
  198.  
  199. // pour message final
  200. extern char end_mirror_msg[8192];
  201. #include "winhttrack.h"
  202. extern CWinHTTrackApp* this_app;
  203.  
  204.  
  205. // PATCH-->
  206. // PATCH-->
  207. // FIN PATCH
  208.  
  209.  
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CShellApp
  212.  
  213. /*
  214. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  215. //{{AFX_MSG_MAP(CShellApp)
  216. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  217. // NOTE - the ClassWizard will add and remove mapping macros here.
  218. //    DO NOT EDIT what you see in these blocks of generated code!
  219. //}}AFX_MSG_MAP
  220. // Standard file based document commands
  221. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  222. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  223. // Standard print setup command
  224. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  225. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  226. END_MESSAGE_MAP()
  227. */
  228.  
  229. /////////////////////////////////////////////////////////////////////////////
  230. // CShellApp construction
  231.  
  232. CShellApp::CShellApp()
  233. {
  234.   // TODO: add construction code here,
  235.   // Place all significant initialization in InitInstance
  236. }
  237.  
  238. /////////////////////////////////////////////////////////////////////////////
  239. // The one and only CShellApp object
  240.  
  241. //CShellApp theApp;
  242.  
  243. /////////////////////////////////////////////////////////////////////////////
  244. // CShellApp initialization
  245.  
  246. UINT RunBackMirror( LPVOID pP ) {
  247.   CShellApp_app->init_lance();
  248.   return 0;
  249. }
  250.  
  251. BOOL LaunchMirror() {
  252.   WHTT_LOCK();
  253.   hts_resetvar();
  254.   WHTT_UNLOCK();
  255.   AfxBeginThread(RunBackMirror,NULL);
  256.   return 0;
  257. }
  258.  
  259. #if 0
  260. BOOL CShellApp::InitInstance()
  261. {
  262.   CShellApp_app=this;
  263.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  264.   
  265.   // Initialize OLE libraries
  266.   /*
  267.   if (!AfxOleInit())
  268.   {
  269.   AfxMessageBox(LANG(LANG_F1));
  270.   return FALSE;
  271.   }
  272.   AfxEnableControlContainer();
  273.   */
  274.   
  275.   // Fixer localisation dans la base de registre
  276.   //SetRegistryKey("WinHTTrack");
  277.   
  278.   // Standard initialization
  279.   // If you are not using these features and wish to reduce the size
  280.   //  of your final executable, you should remove from the following
  281.   //  the specific initialization routines you do not need.
  282.   /*
  283.   #ifdef _AFXDLL
  284.   Enable3dControls();            // Call this when using MFC in a shared DLL
  285.   #else
  286.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  287.   #endif
  288.   */
  289.   
  290.   // Register the application's document templates.  Document templates
  291.   //  serve as the connection between documents, frame windows and views.
  292.   
  293.   // Change the registry key under which our settings are stored.
  294.   // You should modify this string to be something appropriate
  295.   // such as the name of your company or organization.
  296.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  297.   
  298.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  299.   
  300.   // Register the application's document templates.  Document templates
  301.   //  serve as the connection between documents, frame windows and views.
  302.   
  303.   // Parse command line for standard shell commands, DDE, file open
  304.   /*CCommandLineInfo cmdInfo;
  305.   ParseCommandLine(cmdInfo);
  306.   */
  307.   
  308.   _Cinprogress_inst=NULL;
  309.   
  310.   LibRasUse=0;
  311.   
  312.   /*
  313.   #if USE_RAS
  314.   LibRas=new CDynamicRAS();
  315.   if (LibRas->IsRASLoaded()) 
  316.   LibRasUse=1;
  317.   else
  318.   LibRasUse=0;
  319.   #endif
  320.   */
  321.   
  322.   maintab = new CMainTab("WinHTTrack Website Copier");
  323.   
  324.   // PATCH-->
  325.   // ΘxΘcution..
  326.   init_lance();
  327.   
  328.   delete maintab;
  329.   maintab=NULL;
  330.   
  331.   // PATCH-->
  332.   /*
  333.   // Dispatch commands specified on the command line
  334.   if (!ProcessShellCommand(cmdInfo))
  335.         return FALSE;
  336.     
  337.       // The one and only window has been initialized, so show and update it.
  338.       m_pMainWnd->ShowWindow(SW_SHOW);
  339.       m_pMainWnd->UpdateWindow();
  340.   */  
  341.   
  342.   
  343.   return TRUE;
  344. }
  345. #endif
  346.  
  347. // PATCH-->
  348. // routines diverses
  349.  
  350. char* _SN(LLint n) {
  351.   static char str[256];
  352.   str[0]='\0';
  353.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  354.   return str;
  355. }
  356.  
  357. // t existe-t-il comme rΘpertoire?
  358. int dir_check(char* t) {
  359.   int dir;
  360.   FILE* fp=fopen(t,"rb");
  361.   dir=(errno==13);  // is directory
  362.   if (fp) fclose(fp);
  363.   return dir;
  364. }
  365.  
  366. void check_temp(char* t,char* s) {
  367.   if (strlen(s)==0)
  368.     if (dir_check(t))
  369.       strcpybuff(s,t);
  370. }
  371.  
  372.  
  373.  
  374. // PATCH-->
  375. // Routines gestion dials
  376. // PatchΘ pour 100% dials
  377.  
  378.  
  379. void CShellApp::init_lance() {
  380.   hts_init();
  381.   htswrap_add("check-link",httrackengine_check);
  382.   htswrap_add("init",httrackengine_init);
  383.   htswrap_add("free",httrackengine_uninit);
  384.   htswrap_add("start",httrackengine_start);
  385.   htswrap_add("end",httrackengine_end);
  386.   htswrap_add("check-html",httrackengine_htmlcheck);
  387.   htswrap_add("change-options",httrackengine_chopt);
  388.   htswrap_add("loop",httrackengine_loop);
  389.   htswrap_add("query",httrackengine_query);
  390.   htswrap_add("query2",httrackengine_query2);
  391.   htswrap_add("query3",httrackengine_query3);
  392.   htswrap_add("pause",httrackengine_pause);
  393.   
  394.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  395.   lance();             // Lancer miroir!
  396.   if (fp_debug) {
  397.     fprintf(fp_debug,"Building top index\r\n");
  398.     fflush(fp_debug);
  399.   }
  400.   Build_TopIndex();
  401. }
  402.  
  403. /* sauver profile */
  404. /* ask: demande confirmation, si cela vaut le coup */
  405. int Save_current_profile(int ask) {
  406.   CString winprofile;
  407.   if (ask) {
  408.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  409.       return IDNO;
  410.     int r;
  411.     char msg[256];
  412.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  413.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  414.       return r;
  415.   }
  416.   //
  417.   CWaitCursor wait;
  418.   
  419.   // sauver whtt
  420.   {
  421.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  422.     FILE* fp=fopen(st,"wb");
  423.     if (fp) fclose(fp);
  424.   }
  425.   
  426.   // sauver ini
  427.   winprofile=dialog0->GetPath();
  428.   if (winprofile.GetLength()>0)
  429.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  430.       winprofile+="\\";
  431.     winprofile+="hts-cache\\";
  432.     {
  433.       char tempo[HTS_URLMAXSIZE*2];
  434.       int i;
  435.       strcpybuff(tempo,winprofile);
  436.       for(i=0;i<(int)strlen(tempo);i++)
  437.         if (tempo[i]=='\\')
  438.           tempo[i]='/';              
  439.         structcheck(tempo);
  440.     }
  441.     
  442.     winprofile+="winprofile.ini";
  443.     Write_profile(winprofile,0);
  444.     
  445.     // marquer document comme "sauvΘ"
  446.     if (this_CSplitterFrame)
  447.       this_CSplitterFrame->SetSaved();
  448.     
  449.     return IDYES;
  450. }
  451.  
  452. // reprise possible?
  453. int check_continue(char* pathlog) {
  454.   char path_log[256];
  455.   strcpybuff(path_log,pathlog);
  456.   if (strlen(path_log)>0)
  457.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  458.       strcatbuff(path_log,"/");
  459.     if (
  460.       fexist(fconcat(path_log,"hts-cache/new.zip"))
  461.       ||
  462.       (fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))
  463.       ) {  // il existe dΘja un cache prΘcΘdent.. renommer
  464.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  465.       return 1;
  466.       //}
  467.     }
  468.     if (
  469.       fexist(fconcat(path_log,"hts-cache/old.zip"))
  470.       ||
  471.       (fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))
  472.       ) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  473.       return 1;
  474.     }
  475.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  476.     return 0;
  477. }
  478.  
  479.  
  480. void CShellApp::OptPannel() {
  481.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  482.   if (maintab->DoModal()==IDCANCEL) {
  483.     Read_profile("<mem>",0);      // restaurer
  484.   }
  485. }
  486.  
  487.  
  488. #define ADD_MIME_IN_COPT(A) \
  489.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  490.   ShellOptions->buff_MIME += "--assume "; \
  491.   ShellOptions->buff_MIME += maintab->m_option11.m_ext##A; \
  492.   ShellOptions->buff_MIME += "="; \
  493.   ShellOptions->buff_MIME += maintab->m_option11.m_mime##A; \
  494.   ShellOptions->buff_MIME += " "; \
  495.   } \
  496.   
  497. // parser maintab et calculer options
  498. void compute_options() { 
  499.   CWaitCursor wait;
  500.   
  501.   /* Effacer options */
  502.   if (ShellOptions != NULL) {
  503.     delete ShellOptions;
  504.     ShellOptions = NULL;
  505.   }
  506.   ShellOptions = new CShellOptions();
  507.   /* Effacer options */
  508.   
  509.   // Mode de miroir
  510.   switch(dialog1->m_todo) {
  511.   case CB_ERR: case 0:
  512.     ShellOptions->choixdeb = "w";
  513.     break;
  514.   case 1:
  515.     ShellOptions->choixdeb = "W";
  516.     break;
  517.   case 2:
  518.     ShellOptions->choixdeb = "g";
  519.     break;
  520.   case 3:
  521.     ShellOptions->choixdeb = "Y";
  522.     break;
  523.   case 4:
  524.     ShellOptions->choixdeb = "!";
  525.     break;
  526.   default:
  527.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  528.       ShellOptions->choixdeb = "i";    // reprise
  529.     else
  530.       ShellOptions->choixdeb = "/";    // reprise cache prioritaire
  531.     break;
  532.   }
  533.   
  534.   // URLS
  535.   ShellOptions->url = dialog1->m_urls;
  536.   StripControls(ShellOptions->url.GetBuffer(0));
  537.   // --- formation du path
  538.   ShellOptions->path = "\"";
  539.   ShellOptions->path += dialog0->GetPath0();
  540.   ShellOptions->path += "\"";
  541.   ShellOptions->path += ",";
  542.   ShellOptions->path += "\"";
  543.   ShellOptions->path += dialog0->GetPath0();
  544.   ShellOptions->path += "\"";
  545.   
  546.   // filelist
  547.   {
  548.     CString st=dialog1->m_filelist;
  549.     st.TrimLeft();
  550.     st.TrimRight();
  551.     ShellOptions->filelist = st;
  552.   }
  553.   
  554.   // stocker Θtat et hh/mm/ss
  555.   ShellOptions->hh = dialog2->m_hh;
  556.   ShellOptions->mm = dialog2->m_mm;
  557.   ShellOptions->ss = dialog2->m_ss;
  558.   if (ShellOptions->hh.GetLength()) {    // heure
  559.     int x,y,z;
  560.     sscanf(ShellOptions->hh.GetBuffer(0),"%d",&x);
  561.     x=min(max(x,0),23);
  562.     ShellOptions->hh.Format("%d",x);
  563.     //
  564.     sscanf(ShellOptions->mm.GetBuffer(0),"%d",&y);
  565.     y=min(max(y,0),59);
  566.     ShellOptions->mm.Format("%d",y);
  567.     //
  568.     sscanf(ShellOptions->ss.GetBuffer(0),"%d",&z);
  569.     z=min(max(z,0),59);
  570.     ShellOptions->ss.Format("%d",z);
  571.     //
  572.     ShellOptions->waittime = "";
  573.     {
  574.       char str[32];
  575.       ShellOptions->waittime = "#u";
  576.       sprintf(str,"%d",x*3600+y*60+z);
  577.       ShellOptions->waittime += str;
  578.     }
  579.   }
  580.   ShellOptions->_RasString = dialog2->RasString;
  581.   ShellOptions->_dial=dialog2->dial;
  582.   
  583.   if (ShellOptions->choixdeb[0]=='/') {
  584.     ShellOptions->cache = "C1";      // cache prio
  585.   } else {
  586.     if(!maintab->m_option3.m_cache) 
  587.       ShellOptions->cache = "C0"; 
  588.     else 
  589.       ShellOptions->cache = "C2";     // cache non prio 
  590.     //ShellOptions->cache[0]='\0'; 
  591.   }
  592.   
  593.   // ne pas recharger fichiers dΘja pris mais effacΘs
  594.   if(maintab->m_option9.m_norecatch) ShellOptions->norecatch = "%n"; else ShellOptions->norecatch = "";
  595.   
  596.   // proxy
  597.   ShellOptions->proxy = maintab->m_option10.m_proxy;
  598.   ShellOptions->port = maintab->m_option10.m_port;
  599.   if (maintab->m_option10.m_ftpprox) 
  600.     ShellOptions->proxyftp = "%f";
  601.   else
  602.     ShellOptions->proxyftp = "%f0";   
  603.   
  604.   //depth
  605.   ShellOptions->depth = maintab->m_option5.m_depth;
  606.   ShellOptions->extdepth = maintab->m_option5.m_depth2;
  607.   
  608.   if(!maintab->m_option9.m_index) ShellOptions->index = "I0"; else ShellOptions->index = ""; 
  609.   if(!maintab->m_option9.m_index2) ShellOptions->index2 = "%I0"; else ShellOptions->index2 = "%I"; 
  610.   if(maintab->m_option2.m_dos) 
  611.     ShellOptions->dos = "L0"; 
  612.   else if(maintab->m_option2.m_iso9660) 
  613.     ShellOptions->dos = "L2"; 
  614.   else 
  615.     ShellOptions->dos = ""; 
  616.   if(maintab->m_option1.m_testall) ShellOptions->testall = "t"; else ShellOptions->testall = ""; 
  617.   if(maintab->m_option1.m_parseall) ShellOptions->parseall = "%P"; else ShellOptions->parseall = "%P0"; 
  618.   if(maintab->m_option1.m_link) ShellOptions->link = "n"; else ShellOptions->link = ""; 
  619.   if(maintab->m_option1.m_htmlfirst) ShellOptions->htmlfirst = "p7"; else ShellOptions->htmlfirst = ""; 
  620.   if(maintab->m_option2.m_errpage) ShellOptions->errpage = "o0"; else ShellOptions->errpage = ""; 
  621.   if(maintab->m_option2.m_external) ShellOptions->external = "x"; else ShellOptions->external = ""; 
  622.   if(maintab->m_option2.m_nopurge) ShellOptions->nopurge = "X0"; else ShellOptions->nopurge = ""; 
  623.   if(maintab->m_option2.m_hidepwd) ShellOptions->hidepwd = "%x"; else ShellOptions->hidepwd = ""; 
  624.   if(maintab->m_option2.m_hidequery) ShellOptions->hidequery = "%q0"; else ShellOptions->hidequery = ""; 
  625.   
  626.   ShellOptions->robots = "";
  627.   if(maintab->m_option8.m_robots==0) ShellOptions->robots = "s0"; 
  628.   else if(maintab->m_option8.m_robots==1) ShellOptions->robots = "s1"; 
  629.   else if(maintab->m_option8.m_robots==2) ShellOptions->robots = "s2"; 
  630.   
  631.   // cookies,checktype,parsejava
  632.   if(maintab->m_option8.m_cookies==0) ShellOptions->cookies = "b0"; // else ShellOptions->cookies = "b1";
  633.   if (maintab->m_option8.m_checktype>=0)
  634.     ShellOptions->checktype.Format("u%d",maintab->m_option8.m_checktype);
  635.   if(maintab->m_option8.m_parsejava==0) ShellOptions->parsejava = "j0"; // else ShellOptions->cookies = "j1";
  636.   if (maintab->m_option8.m_http10) ShellOptions->http10 = "%h";   // HTTP/1.0 notamment
  637.   if (maintab->m_option8.m_toler)  ShellOptions->toler = "%B";    // tolerent
  638.   if (maintab->m_option8.m_updhack)  ShellOptions->updhack = "%s";    // update hack
  639.   
  640.   // store all in cache,logtype
  641.   if(maintab->m_option9.m_Cache2!=0) ShellOptions->Cache2 = "k";
  642.   if(maintab->m_option9.m_logtype==1) ShellOptions->logtype = "z";
  643.   else if(maintab->m_option9.m_logtype==2) ShellOptions->logtype = "Z";
  644.   if (maintab->m_option3.m_windebug) ShellOptions->logtype += "%H";      // debug headers
  645.   
  646.   ShellOptions->build = "";
  647.   if      (maintab->m_option2.m_build==0) ShellOptions->build = "N0";
  648.   else if (maintab->m_option2.m_build==1) ShellOptions->build = "N1";
  649.   else if (maintab->m_option2.m_build==2) ShellOptions->build = "N2";
  650.   else if (maintab->m_option2.m_build==3) ShellOptions->build = "N3";
  651.   else if (maintab->m_option2.m_build==4) ShellOptions->build = "N4";
  652.   else if (maintab->m_option2.m_build==5) ShellOptions->build = "N5";
  653.   else if (maintab->m_option2.m_build==6) ShellOptions->build = "N100";
  654.   else if (maintab->m_option2.m_build==7) ShellOptions->build = "N101";
  655.   else if (maintab->m_option2.m_build==8) ShellOptions->build = "N102";
  656.   else if (maintab->m_option2.m_build==9) ShellOptions->build = "N103";
  657.   else if (maintab->m_option2.m_build==10) ShellOptions->build = "N104";
  658.   else if (maintab->m_option2.m_build==11) ShellOptions->build = "N105";
  659.   else if (maintab->m_option2.m_build==12) ShellOptions->build = "N99";
  660.   else if (maintab->m_option2.m_build==13) ShellOptions->build = "N199";
  661.   else if (maintab->m_option2.m_build==14) {
  662.     ShellOptions->build = "-N \"";
  663.     ShellOptions->build += maintab->m_option2.Bopt.m_BuildString;
  664.     ShellOptions->build += "\"";
  665.   }
  666.   
  667.   ShellOptions->filtre = "";
  668.   if      (maintab->m_option3.m_filter==0) ShellOptions->filtre = "p0";
  669.   else if (maintab->m_option3.m_filter==1) ShellOptions->filtre = "p1";
  670.   else if (maintab->m_option3.m_filter==2) ShellOptions->filtre = "p2";
  671.   else if (maintab->m_option3.m_filter==3) {    /* default */
  672.     if(!maintab->m_option1.m_htmlfirst) ShellOptions->filtre = "p3";
  673.   }
  674.   else if (maintab->m_option3.m_filter==4) ShellOptions->filtre = "p7";
  675.   //
  676.   if      (maintab->m_option3.m_travel==0) ShellOptions->filtre += "S";
  677.   else if (maintab->m_option3.m_travel==1) ShellOptions->filtre += "D";
  678.   else if (maintab->m_option3.m_travel==2) ShellOptions->filtre += "U";
  679.   else if (maintab->m_option3.m_travel==3) ShellOptions->filtre += "B";
  680.   //
  681.   if      (maintab->m_option3.m_travel2==0) ShellOptions->filtre += "a";
  682.   else if (maintab->m_option3.m_travel2==1) ShellOptions->filtre += "d";
  683.   else if (maintab->m_option3.m_travel2==2) ShellOptions->filtre += "l";
  684.   else if (maintab->m_option3.m_travel2==3) ShellOptions->filtre += "e";
  685.   //
  686.   if      (maintab->m_option3.m_travel3==0) ShellOptions->filtre += "K0";
  687.   else if (maintab->m_option3.m_travel3==1) ShellOptions->filtre += "K";
  688.   else if (maintab->m_option3.m_travel3==2) ShellOptions->filtre += "K3";
  689.   else if (maintab->m_option3.m_travel3==3) ShellOptions->filtre += "K4";
  690.  
  691.   if (maintab->m_option9.m_logf) ShellOptions->log = "f2"; else ShellOptions->log = "Q"; 
  692.   
  693.   if(maintab->m_option5.m_sizemax!=""){
  694.     ShellOptions->max = "M";
  695.     ShellOptions->max += maintab->m_option5.m_sizemax;
  696.   } else ShellOptions->max = "";
  697.   
  698.   if(maintab->m_option5.m_pausebytes!=""){
  699.     ShellOptions->frag = "G";
  700.     ShellOptions->frag += maintab->m_option5.m_pausebytes;
  701.   } else ShellOptions->frag = "";
  702.   
  703.   
  704.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  705.     ShellOptions->maxfile = "m";
  706.     if(maintab->m_option5.m_othermax!="") ShellOptions->maxfile += maintab->m_option5.m_othermax;
  707.     else ShellOptions->maxfile += "0";
  708.     if(maintab->m_option5.m_maxhtml!="") {ShellOptions->maxfile += ",";ShellOptions->maxfile += maintab->m_option5.m_maxhtml;}
  709.     else {ShellOptions->maxfile += ",";ShellOptions->maxfile += "0";}
  710.   } else ShellOptions->maxfile = "";
  711.   
  712.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  713.     ShellOptions->conn = "c";
  714.     ShellOptions->conn += maintab->m_option4.m_connexion;
  715.   } else ShellOptions->conn = "";
  716.   
  717.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  718.     ShellOptions->time = "T";
  719.     ShellOptions->time += maintab->m_option4.m_timeout;
  720.   } else ShellOptions->time = "";
  721.   
  722.   // quitter host si timeout ou rate out
  723.   ShellOptions->hostquit = "";
  724.   {
  725.     int a=0;
  726.     if (maintab->m_option4.m_remt)
  727.       a+=1;
  728.     if (maintab->m_option4.m_rems)
  729.       a+=2;
  730.     ShellOptions->hostquit.Format("H%d",a);
  731.   }
  732.  
  733.   // Keep-Alive
  734.   if (maintab->m_option4.m_ka) {
  735.     ShellOptions->ka = "%k";
  736.   } else {
  737.     ShellOptions->ka = "%k0";
  738.   }
  739.  
  740.   
  741.   //--> max time
  742.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  743.     ShellOptions->maxtime = "E";
  744.     ShellOptions->maxtime += maintab->m_option5.m_maxtime;
  745.   } else ShellOptions->maxtime = "";
  746.   
  747.   //--> max rate
  748.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  749.     ShellOptions->maxrate = "A";
  750.     ShellOptions->maxrate += maintab->m_option5.m_maxrate;
  751.   } else ShellOptions->maxrate = "";
  752.   
  753.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  754.     ShellOptions->maxconn = "%c";
  755.     ShellOptions->maxconn += maintab->m_option5.m_maxconn;
  756.   } else ShellOptions->maxconn = "";
  757.   
  758.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  759.     ShellOptions->maxlinks = "#L";
  760.     ShellOptions->maxlinks += maintab->m_option5.m_maxlinks;
  761.   } else ShellOptions->maxlinks = "";
  762.   
  763.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  764.     ShellOptions->rate = "J";
  765.     ShellOptions->rate += maintab->m_option4.m_rate;
  766.   } else ShellOptions->rate = "";
  767.   
  768.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  769.     ShellOptions->user = "\"";
  770.     ShellOptions->user += maintab->m_option6.m_user;
  771.     ShellOptions->user += "\"";
  772.   } else ShellOptions->user = "";
  773.   
  774.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  775.     ShellOptions->footer = "\"";
  776.     ShellOptions->footer += maintab->m_option6.m_footer;
  777.     ShellOptions->footer += "\"";
  778.   } else ShellOptions->footer = "";
  779.   
  780.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  781.     ShellOptions->retry = "R";
  782.     ShellOptions->retry += maintab->m_option4.m_retry;
  783.   } else ShellOptions->retry = "";
  784.   
  785.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  786.     ShellOptions->buff_filtres = maintab->m_option7.m_url2;
  787.   } else ShellOptions->buff_filtres = "";
  788.   
  789.   
  790.   // MIME
  791.   ShellOptions->buff_MIME = "";
  792.   ADD_MIME_IN_COPT(1)
  793.     ADD_MIME_IN_COPT(2)
  794.     ADD_MIME_IN_COPT(3)
  795.     ADD_MIME_IN_COPT(4)
  796.     ADD_MIME_IN_COPT(5)
  797.     ADD_MIME_IN_COPT(6)
  798.     ADD_MIME_IN_COPT(7)
  799.     ADD_MIME_IN_COPT(8)
  800.     
  801.     /* autres options: RAS */
  802.     if (dialog2->m_rasdisc)
  803.       disconnect=1;     /* dΘconnexion α la fin */
  804.     else
  805.       disconnect=0;
  806.  
  807.     /* autres options: Shutdown */
  808.     if (dialog2->m_rasshut)
  809.       shutdown_pc=1;     /* Θtendre α la fin */
  810.     else
  811.       shutdown_pc=0;
  812. }
  813.  
  814. // Les routines α dΘfinir:
  815. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  816.   return -1;
  817. }
  818. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  819. #if USE_RAS
  820.   has_started=0;
  821. #endif
  822.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  823.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  824. }
  825. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  826. #if USE_RAS
  827.   if (LibRasUse) {        /* librairie RAS chargΘe */
  828.     if (disconnect) {     /* on doit dΘconnecter */
  829.       if (connected) {    /* on a initiΘ une connexion */
  830.         if (conn)
  831.           LibRas->RasHangUp(conn);
  832.       } else {            /* tout dΘconnecter */
  833.         // On coupe tout (non, pas bourrin)
  834.         DWORD size;
  835.         RASCONN* adr;
  836.         int count=256;
  837.         size = sizeof(RASCONN)*(count+2);
  838.         adr = (RASCONN*) (char*) calloc(size,1);
  839.         if (adr) {
  840.           DWORD ent;
  841.           int i;
  842.           for(i=0;i<count;i++) {
  843.             adr[i].dwSize=sizeof(RASCONN);
  844.             strcpybuff(adr[i].szEntryName,"");
  845.           }
  846.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  847.             for(i=0;i<(int)ent;i++) {
  848.               LibRas->RasHangUp(adr[i].hrasconn);
  849.             }
  850.           }
  851.           free(adr);
  852.         }
  853.         
  854.       }
  855.     }
  856.     if (shutdown_pc) {
  857.       ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF /*| EWX_FORCEIFHUNG*/, 0);
  858.     }
  859.   }
  860. #endif
  861. }
  862. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  863. #if USE_RAS
  864.   // connexion RAS
  865.   has_started=1;    // dΘmarrage
  866.   connected=0;
  867.   conn = NULL;
  868.   memset(&SInfo, 0, sizeof(SInfo));
  869.   if (LibRasUse) {
  870.     if (ShellOptions->_RasString.GetLength()>0) {    // sΘlection provider
  871.       if (!LibRas->RasDial(NULL,NULL,&ShellOptions->_dial,NULL,NULL,&conn)) {
  872.         RASCONNSTATUS status;
  873.         do {
  874.           status.dwSize = sizeof(status);
  875.           LibRas->RasGetConnectStatus(conn,&status);
  876.           switch(status.rasconnstate) {
  877.           case RASCS_Connected : 
  878.             connected=1;
  879.             break;
  880.           case RASCS_Disconnected :
  881.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  882.             connected=-1;
  883.             break;
  884.           }
  885.         } while(connected==0);
  886.       } else {
  887.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  888.         connected=-1;
  889.         //termine=1;
  890.       }
  891.     }
  892.     //
  893.     if (connected != -1)  // si pas d'erreur RAS
  894.       return 1;
  895.     else
  896.       return 0;
  897.   } else
  898.     return 1;
  899. #else
  900.   return 1;
  901. #endif
  902. }
  903. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  904.   WHTT_LOCK();
  905.   termine=1;
  906.   if (_Cinprogress_inst) {
  907.     _Cinprogress_inst->EndDialog(IDOK);
  908.     _Cinprogress_inst=NULL;
  909.   }
  910.   WHTT_UNLOCK();
  911.   return 1;
  912. }
  913. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  914.   return 1;
  915. }
  916. int __cdecl httrackengine_chopt(void* opt) {
  917.   return 1;
  918. }
  919.  
  920. // Le routine la plus utile sans doute: elle refresh les tableaux
  921. // C'est la 2e routine en thread qui assure le refresh graphique
  922. // (plus efficace)
  923. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  924. int __cdecl httrackengine_loop(
  925.                                void* _back,int back_max,int back_index,
  926.                                int lien_n,int lien_tot,
  927.                                int stat_time,
  928.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  929.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  930.   int stat_written=-1;
  931.   int stat_updated=-1;
  932.   int stat_errors=-1;
  933.   int stat_warnings=-1;
  934.   int stat_infos=-1;
  935.   int nbk=-1;
  936.   LLint nb=-1;
  937.   int stat_nsocket=-1;
  938.   LLint stat_bytes=-1;
  939.   LLint stat_bytes_recv=-1;
  940.   int irate=-1;
  941.   
  942.   WHTT_LOCK();
  943.  
  944.   if (stats) {
  945.     stat_written=stats->stat_files;
  946.     stat_updated=stats->stat_updated_files;
  947.     stat_errors=stats->stat_errors;
  948.     stat_warnings=stats->stat_warnings;
  949.     stat_infos=stats->stat_infos;
  950.     nbk=stats->nbk;
  951.     stat_nsocket=stats->stat_nsocket;
  952.     irate=(int)stats->rate;
  953.     nb=stats->nb;
  954.     stat_bytes=stats->nb;
  955.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  956.   }
  957.   
  958. #if !SHELL_MULTITHREAD
  959.   static TStamp last_time;
  960. #endif
  961.   int rate;
  962.   // casts
  963.   lien_back* back=(lien_back*) _back;
  964.   //  static int ft=-1;
  965.   
  966.   if (back_max == 0) {
  967. #if !SHELL_MULTITHREAD
  968.     last_time=0;
  969. #endif
  970.     // en cas de manque de time
  971.     SInfo.refresh=1;
  972.     SInfo.stat_timestart=time_local();
  973.     WHTT_UNLOCK();
  974.     return 1;
  975.   }
  976.   
  977.   if ((termine) || (termine_requested)) {
  978.     SInfo.refresh=0;      // pas de refresh
  979.     SInfo.refresh=0;      // pas de refresh
  980.     termine_requested=1;
  981.     WHTT_UNLOCK();
  982.     return 0;
  983.   }
  984.   
  985.   if (stat_written>=0) SInfo.stat_written=stat_written;
  986.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  987.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  988.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  989.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  990.   
  991. #if SHELL_MULTITHREAD 
  992.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  993.   if (SInfo.ask_refresh) {
  994. #else
  995.     TStamp tl=0;
  996.     {
  997.       time_t tt;
  998.       struct tm* A;
  999.       tt=time(NULL);
  1000.       A=localtime(&tt);
  1001.       tl+=A->tm_sec;
  1002.       tl+=A->tm_min*60;
  1003.       tl+=A->tm_hour*60*60;
  1004.       //tl+=A->tm_yday*60*60*24;
  1005.       //tl+=A->tm_year*60*60*24*365;
  1006.       
  1007.       tl*=1000;  // en ms
  1008.       
  1009.       struct _timeb timebuffer;
  1010.       char *timeline;
  1011.       _ftime( &timebuffer );
  1012.       timeline = ctime( & ( timebuffer.time ) );
  1013.       
  1014.       tl+=timebuffer.millitm;    // + ms
  1015.     }
  1016.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1017.       last_time=tl;
  1018. #endif
  1019.       //INFILLMEM_LOCKED=1;    // locker interface
  1020.       // OPTI int rate;
  1021.       SInfo.ask_refresh=0;
  1022.       
  1023.       // pour Θviter temps cpu consommΘ trop grand
  1024.       // Sleep(10);
  1025.       
  1026.       // initialiser ft
  1027.       if ((stat_nsocket==-1)) {
  1028.         if (SInfo.ft==-1) {
  1029.           SInfo.ft=stat_time;
  1030.         }
  1031.       }
  1032.       
  1033. #if !SHELL_MULTITHREAD
  1034.       //
  1035.       MSG msg;  
  1036.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1037.         switch (msg.message) {
  1038.         case WM_COMMAND:        
  1039.           switch(msg.wParam) { 
  1040.           case ID_APP_ABOUT: {
  1041.             Cabout about;
  1042.             about.DoModal();                                    }
  1043.             break;
  1044.           case ID_APP_EXIT: case WM_CLOSE :
  1045.             termine_requested=1;
  1046.             break;
  1047.           case  WM_DESTROY: case WM_NCDESTROY: 
  1048.             termine_requested=1;
  1049.             break;
  1050.           }
  1051.           break;        
  1052.           default:
  1053.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1054.             break;
  1055.         }
  1056.       }
  1057.       //
  1058. #endif
  1059.       
  1060.       // calculer heure si ce n'est dΘja fait
  1061.       if (stat_time<0)
  1062.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1063.       
  1064.       // calculer transfer rate
  1065.       if ((stat_time>0) && (stat_bytes_recv>0))
  1066.         rate=(int)(stat_bytes_recv/stat_time);
  1067.       else
  1068.         rate=0;    // pas d'infos
  1069.       
  1070.       // stocker infos: octets transfΘrΘs, temps, etc.
  1071.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1072.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1073.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1074.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1075.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1076.       if (rate>0)  SInfo.rate=rate;                // rate
  1077.       if (irate>=0) SInfo.irate=irate;             // irate
  1078.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1079.       if (nbk>=0) SInfo.stat_back=nbk;
  1080.       
  1081.       // back: tableau de back_max ΘlΘments de cache
  1082.       // back_max: nombre d'ΘlΘments ^^^^
  1083.       // lien_tot: nombre total de liens traitΘs pour le moment
  1084.       // stat_bytes: octets sauvegardΘs
  1085.       // stat_bytes_recv: octets tΘlΘchargΘs
  1086.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1087.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1088.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1089.       
  1090.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1091.       
  1092.       // parcourir registre des liens
  1093.       if (back_index>=0) {  // seulement si index passΘ
  1094.         int j,k;
  1095.         int index=0;
  1096.         int ok=0;         // idem
  1097.         int l;            // idem
  1098.         int M=32;         // idem
  1099.         
  1100.         StatsBufferback=(void*) back;
  1101.         StatsBufferback_max=back_max;
  1102.         {
  1103.           int i;
  1104.           for(i=0;i<NStatsBuffer;i++) {
  1105.             strcpybuff(StatsBuffer[i].etat,"");
  1106.             strcpybuff(StatsBuffer[i].nom,"");
  1107.             strcpybuff(StatsBuffer[i].fichier,"");
  1108.             strcpybuff(StatsBuffer[i].url_sav,"");
  1109.             StatsBuffer[i].back=NULL;
  1110.             StatsBuffer[i].size=0;
  1111.             StatsBuffer[i].sizetot=0;
  1112.           }
  1113.         }
  1114.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1115.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1116.             int _i;
  1117.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1118.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1119.               if (back[i].status>=0) {     // signifie "lien actif"
  1120.                 // int ok=0;  // OPTI
  1121.                 ok=0;
  1122.                 switch(j) {
  1123.                 case 0:     // prioritaire
  1124.                   if ((back[i].status>0) && (back[i].status<99)) {
  1125.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1126.                   }
  1127.                   break;
  1128.                 case 1:
  1129.                   if (back[i].status==99) {
  1130.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1131.                   }
  1132.                   else if (back[i].status==100) {
  1133.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1134.                   }
  1135.                   else if (back[i].status==101) {
  1136.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1137.                   }
  1138.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1139.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1140.                   }
  1141.                   else if (back[i].status==102) {         // SSL handshake
  1142.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1143.                   }
  1144.                   else if (back[i].status==-103) {         // waiting (keep-alive)
  1145.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8)); ok=1;
  1146.                   }
  1147.                   break;
  1148.                 default:
  1149.                   if (back[i].status==0) {  // prΩt
  1150.                     if ((back[i].r.statuscode==200)) {
  1151.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1152.                     }
  1153.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1154.                       char tempo[256]; tempo[0]='\0';
  1155.                       infostatuscode(tempo,back[i].r.statuscode);
  1156.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1157.                     }
  1158.                     else {
  1159.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1160.                     }
  1161.                   }
  1162.                   break;
  1163.                 }
  1164.                 
  1165.                 if (ok) {
  1166.                   // OPTI int l;
  1167.                   // OPTI int M=32;     // longueur
  1168.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1169.                   //
  1170.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1171.                   //
  1172.                   s[0]='\0';
  1173.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1174.                   if (strcmp(back[i].url_adr,"file://"))
  1175.                     strcatbuff(s,back[i].url_adr);
  1176.                   else
  1177.                     strcatbuff(s,"localhost");
  1178.                   if (back[i].url_fil[0]!='/')
  1179.                     strcatbuff(s,"/");
  1180.                   strcatbuff(s,back[i].url_fil);
  1181.                   
  1182.                   StatsBuffer[index].fichier[0]='\0';
  1183.                   {
  1184.                     char* a=strrchr(s,'/');
  1185.                     if (a) {
  1186.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1187.                       *a='\0';
  1188.                     }
  1189.                   }
  1190.                   
  1191.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1192.                     strcpybuff(StatsBuffer[index].nom,s);
  1193.                   else {
  1194.                     // couper
  1195.                     StatsBuffer[index].nom[0]='\0';
  1196.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1197.                     strcatbuff(StatsBuffer[index].nom,"...");
  1198.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1199.                   }
  1200.                   
  1201.                   //if (back[i].url_fil[0]!='/') printf("/");
  1202.                   
  1203.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1204.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1205.                     StatsBuffer[index].size=back[i].r.size;
  1206.                   } else {  // pas de taille prΘdΘfinie
  1207.                     if (back[i].status==0) {  // prΩt
  1208.                       StatsBuffer[index].sizetot=back[i].r.size;
  1209.                       StatsBuffer[index].size=back[i].r.size;
  1210.                     } else {
  1211.                       StatsBuffer[index].sizetot=8192;
  1212.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1213.                     }
  1214.                   }
  1215.                   index++;
  1216.                 }
  1217.               }
  1218.             }
  1219.           }
  1220.         }
  1221.     }
  1222.     
  1223. #if SHELL_MULTITHREAD
  1224.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1225. #else
  1226.     inprogress_refresh();  // tout de suite (non multithread)
  1227. #endif
  1228.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1229.   }
  1230.   WHTT_UNLOCK();
  1231.   return (termine==0);
  1232. }
  1233.  
  1234. int inprogress_refresh() {
  1235.   static int toggle=0;
  1236.   // WHTT_LOCK(); // deja fait
  1237.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1238.     if (SInfo.refresh) {
  1239.       // INREDRAW_LOCKED=1;
  1240.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1241.       int icn;
  1242.       icn=inprogress->IsIconic();
  1243.       CString lnk;
  1244.       if (SInfo.stat_back)
  1245.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1246.       else
  1247.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1248.       if (!icn) {
  1249.         int parsing=0;
  1250.         if (!soft_term_requested) {
  1251.           if (!hts_setpause(-1)) {
  1252.             if (!(parsing=hts_is_parsing(-1)))
  1253.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1254.             else {
  1255.               switch(hts_is_testing()) {
  1256.               case 0:
  1257.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1258.                 break;
  1259.               case 1:
  1260.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1261.                 break;
  1262.               case 2:
  1263.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11b)); 
  1264.                 break;
  1265.               case 3:
  1266.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11c)); 
  1267.                 break;
  1268.               }
  1269.             }
  1270.           } else {
  1271.             if (((toggle++)/5)%2)
  1272.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1273.             else
  1274.               SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1275.           }
  1276.         } else {
  1277.           if (((toggle++)/5)%2)
  1278.             SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13b));
  1279.           else
  1280.             SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1281.         }
  1282.         
  1283.         if (SInfo.stat_time>0) {
  1284.           char s[256];
  1285.           qsec2str(s,(TStamp) SInfo.stat_time);
  1286.           SetDlgItemTextCP(inprogress, IDC_i1 ,s);  // time
  1287.         } else
  1288.           SetDlgItemTextCP(inprogress, IDC_i1 , _SN(SInfo.stat_time) );  // time
  1289.         SetDlgItemTextCP(inprogress, IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1290.         SetDlgItemTextCP(inprogress, IDC_i2 , lnk);  // scanned
  1291.         if (SInfo.stat_nsocket>0)
  1292.           SetDlgItemTextCP(inprogress, IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1293.         else
  1294.           SetDlgItemTextCP(inprogress, IDC_i3 , "none" );  // wait
  1295.         
  1296.         CString st;
  1297.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1298.         SetDlgItemTextCP(inprogress, IDC_i4 , st );  // rate
  1299.         
  1300.         SetDlgItemTextCP(inprogress, IDC_i5 , _SN(SInfo.stat_errors) );
  1301.         SetDlgItemTextCP(inprogress, IDC_i6 , _SN(SInfo.stat_written) );
  1302.         {
  1303.           char tempo[256];
  1304.           int pc=0;
  1305.           if (SInfo.stat_written)
  1306.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1307.           if (pc)
  1308.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1309.           else
  1310.             sprintf(tempo,"%d",SInfo.stat_updated);
  1311.           SetDlgItemTextCP(inprogress, IDC_i7 , tempo );
  1312.         }
  1313.         
  1314.         /*if (!parsing)*/
  1315.         {
  1316.           {
  1317.             int i;
  1318.             for(i=0;i<NStatsBuffer;i++) {
  1319.               if (StatsBuffer[i].sizetot>0) {
  1320.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1321.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1322.                 StatsBuffer[i].offset = (int) d;
  1323.               } else
  1324.                 StatsBuffer[i].offset = 0;
  1325.             }
  1326.           }
  1327.           
  1328.           if (!parsing)
  1329.             inprogress->m_sl0.SetRange(0,1000);
  1330.           inprogress->m_sl1.SetRange(0,1000);
  1331.           inprogress->m_sl2.SetRange(0,1000);
  1332.           inprogress->m_sl3.SetRange(0,1000);
  1333.           inprogress->m_sl4.SetRange(0,1000);
  1334.           inprogress->m_sl5.SetRange(0,1000);
  1335.           inprogress->m_sl6.SetRange(0,1000);
  1336.           inprogress->m_sl7.SetRange(0,1000);
  1337.           inprogress->m_sl8.SetRange(0,1000);
  1338.           inprogress->m_sl9.SetRange(0,1000);
  1339.           inprogress->m_sl10.SetRange(0,1000);
  1340.           inprogress->m_sl11.SetRange(0,1000);
  1341.           inprogress->m_sl12.SetRange(0,1000);
  1342.           inprogress->m_sl13.SetRange(0,1000);
  1343.           
  1344.           if (!parsing)
  1345.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1346.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1347.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1348.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1349.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1350.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1351.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1352.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1353.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1354.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1355.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1356.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1357.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1358.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1359.           
  1360.           // redraw en boucle
  1361.           {
  1362.             int i=0;
  1363.             if (parsing)
  1364.               i++;
  1365.             for( ; i<NStatsBuffer;i++) {
  1366.               CString st;
  1367.               st = StatsBuffer[i].etat;
  1368.               st.Replace("&", "&&");
  1369.               SetWindowTextCP(inprogress->element[0][i], st);
  1370.               st = StatsBuffer[i].nom;
  1371.               st.Replace("&", "&&");
  1372.               SetWindowTextCP(inprogress->element[1][i], st);
  1373.               st = StatsBuffer[i].fichier;
  1374.               st.Replace("&", "&&");
  1375.               SetWindowTextCP(inprogress->element[4][i], st);
  1376.               
  1377.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1378.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1379.                 if (!StatsBuffer[i].actived)
  1380.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1381.                 else
  1382.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1383.                 inprogress->element[3][i]->RedrawWindow();
  1384.               }
  1385.             }
  1386.           }
  1387.           //
  1388.         }
  1389.         /* else*/
  1390.         if (parsing) {  // parsing
  1391.           //
  1392.           inprogress->m_sl0.SetRange(0,100);
  1393.           inprogress->m_sl0.SetPos(parsing);
  1394.           SetWindowTextCP(inprogress->element[0][0], LANG(LANG_F14 /*"scanning","parcours"*/));
  1395.           SetWindowTextCP(inprogress->element[1][0], StatsBuffer[0].nom);
  1396.           SetWindowTextCP(inprogress->element[4][0], "");
  1397.           //inprogress->element[0][1]->SetWindowTextCP(this, );
  1398.         }
  1399.         
  1400.       }
  1401.       {
  1402.         static char last_info[256]="";
  1403.         char info[256];
  1404.         if ((SInfo.stat_nsocket==-1)) {
  1405. #if USE_RAS
  1406.           if (!has_started)
  1407. #endif
  1408.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1409. #if USE_RAS
  1410.           else
  1411.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1412. #endif
  1413.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1414.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1415.           // SetDlgItemTextCP(inprogress, IDC_nm1,_SN(ft));
  1416.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1417.             sprintf(info,"[%d s]",SInfo.stat_time);
  1418.           } else {
  1419.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1420.           }
  1421.         } else {
  1422.           if (icn) {  // minimisΘe
  1423.             sprintf(info,"[%s]",lnk);
  1424.           } else {
  1425.             char byteb[256];
  1426.             sprintf(byteb, LLintP, SInfo.stat_bytes);
  1427.             sprintf(info,LANG(LANG_F18),lnk,byteb);
  1428.           }
  1429.         }
  1430.         if (strcmp(info,last_info)) {       /* a changΘ */
  1431.           strcpybuff(last_info,info);           /* recopier */
  1432.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1433.             this_CSplitterFrame->IconChange(last_info);
  1434.           else
  1435.             SetWindowTextCP(this_app->GetMainWnd(), last_info);
  1436.         }
  1437.       }  
  1438.       
  1439.       //inprogress->UpdateWindow();
  1440.     } else {
  1441.     }
  1442.   }
  1443.   // WHTT_UNLOCK();
  1444.   return 1;
  1445. }
  1446.  
  1447. /*
  1448. // refresh scan
  1449. int inprogress_refresh_scan() {
  1450. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1451. if (!SInfo.refresh) {
  1452. if (!inprogress->IsIconic()) {
  1453. int n;
  1454. // patch pour le scanning
  1455. if (n=hts_is_parsing()) {
  1456. strcpybuff(StatsBuffer[0].etat,"scanning");
  1457. inprogress->element[0][0]->SetWindowTextCP(this, "scanning");
  1458. StatsBuffer[0].sizetot=100;
  1459. StatsBuffer[0].size=n;
  1460. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1461. inprogress->m_sl0.SetPos(n);
  1462. //} else {
  1463. //  inprogress->element[0][0]->SetWindowTextCP(this, "...");
  1464. }
  1465. }
  1466. }
  1467. }
  1468. return 1;
  1469. }
  1470. */
  1471.  
  1472. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1473. char* __cdecl httrackengine_query(char* question) {
  1474.   strcpybuff(WIZ_question,question);
  1475.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1476.   return WIZ_reponse;
  1477. }
  1478.  
  1479. char* __cdecl httrackengine_query2(char* question) {
  1480.   strcpybuff(WIZ_question,question);
  1481.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1482.   return WIZ_reponse;
  1483. }
  1484.  
  1485. char* __cdecl httrackengine_query3(char* question) {
  1486.   strcpybuff(WIZ_question,question);
  1487.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1488.   return WIZ_reponse;
  1489. }
  1490.  
  1491. void __cdecl httrackengine_pause(char* lockfile) {
  1492.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1493.   remove(lockfile);
  1494. }
  1495.  
  1496. // modif RX 10/10/98 pour gestion des , et des tabs
  1497. static void StripControls(char* chaine)
  1498. {
  1499.   for(int i=0 ; chaine[i] != '\0' ; i++)
  1500.   {
  1501.     if(chaine[i]=='\n' || chaine[i]==13 || chaine[i]==9) {
  1502.       chaine[i]=' ';
  1503.     }
  1504.   }
  1505. }
  1506.  
  1507.  
  1508. #if SHELL_MULTITHREAD
  1509. void __cdecl RunBackRobot(void* al_p) {
  1510.   int argc;
  1511.   char** argv;
  1512.   
  1513.   while((!inprogress) && (!termine)) Sleep(10);
  1514.   if (inprogress)
  1515.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1516.     //Sleep(100);
  1517.     
  1518.     Robot_params* al=(Robot_params*) al_p;
  1519.     argc = al->argc;
  1520.     argv = al->argv;
  1521.     /* launch the engine */
  1522.     hts_init();
  1523.     HTTRACK_result=hts_main(argc,argv);
  1524.     /* clear all vars */
  1525.     WHTT_LOCK();
  1526.     termine=1;
  1527.     WHTT_UNLOCK();
  1528.     hts_uninit();
  1529.     
  1530.     _endthread();
  1531. }
  1532. #endif
  1533.  
  1534. // modifs RX 10/10/98: gestion des ,
  1535. CString change(char* chaine,char c) {
  1536.   int comma=1; int first=1;
  1537.   CString chaine1;
  1538.   for(int i=0;i < (int) strlen(chaine);i++) {
  1539.     switch(chaine[i]) {
  1540.     case 10: case 13: case 9: case ' ': case ',':
  1541.       comma=1; 
  1542.       break;
  1543.     default:
  1544.       if (comma) {
  1545.         if (!first) chaine1 +=' ';
  1546.         else first=0; 
  1547.         chaine1  +=c; 
  1548.         comma=0;
  1549.       }
  1550.       chaine1 += chaine[i]; 
  1551.       break;
  1552.     }
  1553.   }
  1554.   return chaine1;
  1555. }
  1556.  
  1557.  
  1558. // Lancement
  1559. void lance(void) {
  1560.   char **argv;
  1561.   int argvAlloc = 1024;
  1562.   int argc=1;
  1563.   int g=0;
  1564.   int i =0;
  1565.   
  1566.   //
  1567.   if (fp_debug) {
  1568.     fprintf(fp_debug,"Building command line\r\n");
  1569.     fflush(fp_debug);
  1570.   }
  1571.   //
  1572.   ShellOptions->LINE = "";
  1573.   ShellOptions->LINE = "-";
  1574.   if (ShellOptions->choixdeb[0]!='W')
  1575.     ShellOptions->LINE += "q";         // quiet
  1576.   
  1577.   if (ShellOptions->choixdeb[0]=='/')
  1578.     ShellOptions->LINE += "i";
  1579.   else if (ShellOptions->choixdeb[0]!='!')
  1580.     ShellOptions->LINE += ShellOptions->choixdeb;
  1581.   // option de profondeur
  1582.   if(strcmp(ShellOptions->depth,"")!=0) { 
  1583.     ShellOptions->LINE += "r";
  1584.     ShellOptions->LINE += ShellOptions->depth;
  1585.   }
  1586.   if(strcmp(ShellOptions->extdepth,"")!=0) { 
  1587.     ShellOptions->LINE += "%e";
  1588.     ShellOptions->LINE += ShellOptions->extdepth;
  1589.   }
  1590.   if(strcmp(ShellOptions->cache,"")!=0) ShellOptions->LINE += ShellOptions->cache;
  1591.   if(strcmp(ShellOptions->norecatch,"")!=0) ShellOptions->LINE += ShellOptions->norecatch;
  1592.   if(strcmp(ShellOptions->testall,"")!=0) ShellOptions->LINE += ShellOptions->testall;
  1593.   if(strcmp(ShellOptions->parseall,"")!=0) ShellOptions->LINE += ShellOptions->parseall;
  1594.   if(strcmp(ShellOptions->link,"")!=0) ShellOptions->LINE += ShellOptions->link;
  1595.   if(strcmp(ShellOptions->external,"")!=0) ShellOptions->LINE += ShellOptions->external;
  1596.   if(strcmp(ShellOptions->nopurge,"")!=0) ShellOptions->LINE += ShellOptions->nopurge;
  1597.   if(strcmp(ShellOptions->hidepwd,"")!=0) ShellOptions->LINE += ShellOptions->hidepwd;
  1598.   if(strcmp(ShellOptions->hidequery,"")!=0) ShellOptions->LINE += ShellOptions->hidequery;
  1599.   if(strcmp(ShellOptions->robots,"")!=0) ShellOptions->LINE += ShellOptions->robots;
  1600.   if(strcmp(ShellOptions->cookies,"")!=0) ShellOptions->LINE += ShellOptions->cookies;
  1601.   if(strcmp(ShellOptions->checktype,"")!=0) ShellOptions->LINE += ShellOptions->checktype;
  1602.   if(strcmp(ShellOptions->parsejava,"")!=0) ShellOptions->LINE += ShellOptions->parsejava;
  1603.   if(strcmp(ShellOptions->Cache2,"")!=0) ShellOptions->LINE += ShellOptions->Cache2;
  1604.   if(strcmp(ShellOptions->logtype,"")!=0) ShellOptions->LINE += ShellOptions->logtype;
  1605.   if (ShellOptions->http10.GetLength()) ShellOptions->LINE += ShellOptions->http10;
  1606.   if (ShellOptions->toler.GetLength()) ShellOptions->LINE += ShellOptions->toler;
  1607.   if (ShellOptions->updhack.GetLength()) ShellOptions->LINE += ShellOptions->updhack;
  1608.   
  1609.   // si get, ne pas faire
  1610.   if (strcmp(ShellOptions->choixdeb,"g")!=0) {
  1611.     if(ShellOptions->build[0]=='-') {
  1612.       ShellOptions->LINE += " ";
  1613.       ShellOptions->LINE += ShellOptions->build;
  1614.       ShellOptions->LINE += " -";
  1615.     } else if (strcmp(ShellOptions->build,"")!=0) ShellOptions->LINE += ShellOptions->build;
  1616.   }
  1617.   ShellOptions->LINE += ShellOptions->dos;
  1618.   ShellOptions->LINE += ShellOptions->index;
  1619.   ShellOptions->LINE += ShellOptions->index2;
  1620.   ShellOptions->LINE += ShellOptions->htmlfirst;
  1621.   ShellOptions->LINE += ShellOptions->filtre;
  1622.   ShellOptions->LINE += ShellOptions->max;
  1623.   ShellOptions->LINE += ShellOptions->frag;
  1624.   ShellOptions->LINE += ShellOptions->maxfile;
  1625.   ShellOptions->LINE += ShellOptions->conn;
  1626.   ShellOptions->LINE += ShellOptions->time;
  1627.   ShellOptions->LINE += ShellOptions->rate;
  1628.   ShellOptions->LINE += ShellOptions->retry;
  1629.   ShellOptions->LINE += ShellOptions->hostquit;
  1630.   ShellOptions->LINE += ShellOptions->ka;
  1631.   ShellOptions->LINE += ShellOptions->log;
  1632.   ShellOptions->LINE += ShellOptions->errpage;
  1633.   //-->
  1634.   ShellOptions->LINE += ShellOptions->waittime;
  1635.   ShellOptions->LINE += ShellOptions->maxtime;
  1636.   ShellOptions->LINE += ShellOptions->maxrate;
  1637.   ShellOptions->LINE += ShellOptions->maxconn;
  1638.   ShellOptions->LINE += ShellOptions->maxlinks;
  1639.   ShellOptions->LINE += ShellOptions->proxyftp;  
  1640.   ShellOptions->LINE += "#f";  // flush
  1641.   
  1642.   if (strcmp(ShellOptions->user,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->user;}
  1643.   if (strcmp(ShellOptions->footer,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-%F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->footer;}
  1644.   
  1645.   if ((int)ShellOptions->proxy.GetLength()>0) {
  1646.     ShellOptions->LINE += " -P ";
  1647.     ShellOptions->LINE += ShellOptions->proxy;
  1648.     ShellOptions->LINE += ":";
  1649.     ShellOptions->LINE += ShellOptions->port;
  1650.   }
  1651.   
  1652.   if (strnotempty(LANGUAGE_ISO)) {
  1653.     ShellOptions->LINE += " -%l \"";
  1654.     ShellOptions->LINE += LANGUAGE_ISO;
  1655.     if (LANGUAGE_ISO != "en")
  1656.       ShellOptions->LINE += ", en";
  1657.     ShellOptions->LINE += ", *\"";
  1658.   }
  1659.   
  1660.   // mode spider, mettre aprΦs options
  1661.   if (ShellOptions->choixdeb[0]=='!') {
  1662.     ShellOptions->LINE += " --testlinks";
  1663.   } else if (ShellOptions->choixdeb[0]=='Y') {
  1664.     ShellOptions->LINE += " --mirrorlinks";
  1665.   }
  1666.   
  1667.   // URLs!!
  1668.   ShellOptions->LINE += " ";
  1669.   ShellOptions->LINE += ShellOptions->url;
  1670.   
  1671.   // file list
  1672.   if ((int) ShellOptions->filelist.GetLength()>0) {
  1673.     ShellOptions->LINE += " -%L \"";
  1674.     ShellOptions->LINE += ShellOptions->filelist;
  1675.     ShellOptions->LINE += "\"";
  1676.   }
  1677.   
  1678.   // chemins
  1679.   if(ShellOptions->path != "") {
  1680.     ShellOptions->LINE += " ";
  1681.     ShellOptions->LINE += "-O";
  1682.     ShellOptions->LINE += " ";
  1683.     ShellOptions->LINE += ShellOptions->path;
  1684.   }
  1685.   
  1686.   // buffer -> les + et -
  1687.   if(strcmp(ShellOptions->buff_filtres,"")!=0) {
  1688.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1689.     ShellOptions->LINE += " ";
  1690.     ShellOptions->LINE += ShellOptions->buff_filtres ;
  1691.   }
  1692.   
  1693.   // --assume
  1694.   if (strnotempty(ShellOptions->buff_MIME)) {
  1695.     ShellOptions->LINE += " ";
  1696.     ShellOptions->LINE += ShellOptions->buff_MIME ;
  1697.   }
  1698.   
  1699.   // ---
  1700.   
  1701.   //
  1702.   if (fp_debug) {
  1703.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1704.     fflush(fp_debug);
  1705.   }
  1706.   //
  1707.   // Θpurer cr,lf,tab - double espace -> espace
  1708.   {
  1709.     char *a;
  1710.     while(a=strchr(ShellOptions->LINE,9)) *a=' ';
  1711.     while(a=strchr(ShellOptions->LINE,10)) *a=' ';
  1712.     while(a=strchr(ShellOptions->LINE,13)) *a=' ';
  1713.   }
  1714.   
  1715.   ShellOptions->LINE_back = ShellOptions->LINE;
  1716.   
  1717.   // couper en morceaux
  1718.   {
  1719.     char* p=ShellOptions->LINE.GetBuffer(0);
  1720.     argv = (char**) malloct(argvAlloc * sizeof(char*));
  1721.     argv[0]="winhttrack";
  1722.     do {
  1723.       if (argc >= argvAlloc) {
  1724.         argvAlloc *= 2;
  1725.         argv = (char**) realloct(argv, argvAlloc * sizeof(char*));
  1726.         assertf(argv != NULL);
  1727.       }
  1728.       argv[argc++]=p;
  1729.       p=next_token(p,0);    // prochain token
  1730.       if (p) {
  1731.         *p=0;    // octet nul (tableau)
  1732.         p++;
  1733.       }            
  1734.     } while(p!=NULL);
  1735.   }
  1736.   
  1737.   //
  1738.   if (fp_debug) {
  1739.     fprintf(fp_debug,"Checking doit.log\r\n");
  1740.     fflush(fp_debug);
  1741.   }
  1742.   //
  1743.   // Ok, on lance!
  1744.   if(!termine) {
  1745.     int result=0;
  1746.     {
  1747.       char path_log[HTS_URLMAXSIZE*2];
  1748.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1749.       if (strlen(path_log)>0)
  1750.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1751.           strcatbuff(path_log,"/");
  1752.         
  1753.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1754.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1755.         if (fexist(fconcat(path_log,"hts-cache/new.zip"))
  1756.           || fexist(fconcat(path_log,"hts-cache/new.ndx"))
  1757.           ) {    // un cache est prΘsent
  1758.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1759.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1760.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1761.           if (fp) fclose(fp);
  1762.         }
  1763.         //}
  1764.     }
  1765.     
  1766.     
  1767.     // ---
  1768.     // LANCER LE MIROIR
  1769.     // ---
  1770.     //
  1771.     if (fp_debug) {
  1772.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1773.       fflush(fp_debug);
  1774.     }
  1775.     //
  1776. #if SHELL_MULTITHREAD
  1777.     Robot_params al;
  1778.     al.argc=argc;
  1779.     al.argv=argv;
  1780.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1781.     //_beginthread( RefreshBackRobot , 0, NULL);
  1782.     
  1783.     //
  1784.     if (fp_debug) {
  1785.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1786.       fflush(fp_debug);
  1787.     }
  1788.     //
  1789.     // domodal du refresh
  1790.     /* XXC A SUPPRIMER */
  1791.     while(!termine) {
  1792.       Sleep(100);
  1793.     }
  1794.     //inprogress->DoModal();
  1795.     WHTT_LOCK();
  1796.     shell_terminated=1;
  1797.     result=HTTRACK_result;
  1798.     termine=1;  
  1799.     WHTT_UNLOCK();
  1800.     //
  1801.     if (fp_debug) {
  1802.       fprintf(fp_debug,"Main dialog exited\r\n");
  1803.       fflush(fp_debug);
  1804.     }
  1805.     //
  1806.     
  1807.     // non multithread
  1808. #else
  1809. #error "Non supportΘ"
  1810. #endif
  1811.  
  1812.     /* Aborted mirror or finished? */
  1813.     {
  1814.       char path_log[HTS_URLMAXSIZE*2];
  1815.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1816.       if (strlen(path_log)>0)
  1817.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1818.           strcatbuff(path_log,"/");
  1819.         if (soft_term_requested || termine_requested) {
  1820.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1821.           if (fp)
  1822.             fclose(fp);
  1823.         } else
  1824.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1825.     }
  1826.     
  1827.     //SetForegroundWindow();   // yop en premier plan!
  1828.     //
  1829.     if (fp_debug) {
  1830.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1831.       fflush(fp_debug);
  1832.     }
  1833.     //
  1834.     /* New pannel */
  1835.     if (result) {      // erreur?
  1836.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  1837.       strcatbuff(end_mirror_msg,"\"");
  1838.       strcatbuff(end_mirror_msg,hts_errmsg());
  1839.       strcatbuff(end_mirror_msg,"\"");
  1840.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1841.       strcatbuff(end_mirror_msg,"\"");
  1842.       strcatbuff(end_mirror_msg,ShellOptions->LINE_back);
  1843.       strcatbuff(end_mirror_msg,"\"");
  1844.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1845.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1846.     } else {
  1847.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  1848.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1849.       //        ShellExecute(0,"open",,"","",);
  1850.     }
  1851. #if USE_RAS
  1852.     // erreur ras
  1853.     if (connected == -1)
  1854.       if ((int) strlen(connected_err) > 0)
  1855.         strcpybuff(end_mirror_msg,connected_err);
  1856. #endif
  1857.       {
  1858.         char pathlog[HTS_URLMAXSIZE*2];
  1859.         strcpybuff(pathlog,dialog0->GetPath());
  1860.         Ciplog form;
  1861.         if (strlen(pathlog)>0)
  1862.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1863.             strcatbuff(pathlog,"/");
  1864.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  1865.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1866.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1867.           }
  1868.       }
  1869.       //this_Cinfoend->m_infoend = msg;
  1870.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1871.       if (fp_debug) {
  1872.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1873.         fflush(fp_debug);
  1874.       }
  1875.       /*
  1876.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1877.       // copie de onnewproject() de wid1::
  1878.       CWinApp* pApp = AfxGetApp();
  1879.       CString name = pApp->m_pszHelpFilePath;
  1880.       name=name.Left(name.GetLength()-4);
  1881.       name += ".EXE";
  1882.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1883.       }
  1884.       */
  1885.       if (fp_debug) {
  1886.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1887.         fflush(fp_debug);
  1888.       }
  1889.   }
  1890.   else {
  1891.   }
  1892.  
  1893.   if (argv != NULL)
  1894.     freet(argv);
  1895.   
  1896. }
  1897.  
  1898. // int LANG_T(int);
  1899. // char* LANG(char* english,char* francais);
  1900.  
  1901.  
  1902. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  1903. void SetCombo(CWnd* _this,int id,char* lang_string) {
  1904.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  1905.   CString st=lang_string;
  1906.   st.TrimLeft(); st.TrimRight();
  1907.   if (combo) {
  1908.     st+="\n";         /* end */
  1909.     combo->ResetContent();
  1910.     while(st.GetLength()) {
  1911.       int pos=st.Find('\n');
  1912.       CString item=st.Left(pos);
  1913.       st=st.Mid(pos+1);
  1914.       item.TrimLeft(); item.TrimRight();
  1915.       if (item.GetLength())
  1916.         combo->AddString(item);
  1917.     }
  1918.   }
  1919. }
  1920.  
  1921.  
  1922. // Ecriture profiles
  1923. char* profile_code(char* from) {
  1924.   static char buff[65535];
  1925.   int i;
  1926.   int j;
  1927.   for(i=0,j=0;i<(int) strlen(from);i++) {
  1928.     switch(from[i]) {
  1929.     case '%': 
  1930.       buff[j++]='%';
  1931.       buff[j++]='%';
  1932.       break;
  1933.     case '=': 
  1934.       buff[j++]='%';
  1935.       buff[j++]='3';
  1936.       buff[j++]='d';
  1937.       break;
  1938.     case 13:
  1939.       buff[j++]='%';
  1940.       buff[j++]='0';
  1941.       buff[j++]='d';
  1942.       break;
  1943.     case 10:
  1944.       buff[j++]='%';
  1945.       buff[j++]='0';
  1946.       buff[j++]='a';
  1947.       break;
  1948.     case 9:
  1949.       buff[j++]='%';
  1950.       buff[j++]='0';
  1951.       buff[j++]='9';
  1952.       break;
  1953.     default:
  1954.       buff[j++]=from[i];
  1955.       break;
  1956.     }
  1957.   }
  1958.   buff[j++]='\0';
  1959.   return buff;
  1960. }
  1961. char* profile_decode(char* from) {
  1962.   static char buff[2048];
  1963.   int i;
  1964.   int j;
  1965.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  1966.     if (from[j]=='%') {
  1967.       if (from[j+1]=='%') {
  1968.         buff[i]='%';
  1969.         j+=2;
  1970.       } else {
  1971.         if (strncmp(from+j+1,"0d",2)==0)
  1972.           buff[i]=13;
  1973.         else if (strncmp(from+j+1,"0a",2)==0)
  1974.           buff[i]=10;
  1975.         else if (strncmp(from+j+1,"09",2)==0)
  1976.           buff[i]=9;
  1977.         else if (strncmp(from+j+1,"3d",2)==0)
  1978.           buff[i]='=';
  1979.         else
  1980.           buff[i]=' ';
  1981.         j+=3;
  1982.       }
  1983.     } else
  1984.       buff[i]=from[j++];
  1985.   }
  1986.   buff[i++]='\0';
  1987.   return buff;
  1988. }
  1989. //
  1990. // Ecriture/Lecture profiles
  1991. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  1992.   if (path.IsEmpty()) {
  1993.     CWinApp* pApp = AfxGetApp();
  1994.     pApp->WriteProfileInt(dummy,name,value);
  1995.   } else if (path=="<mem>") {       // buffer
  1996.     tmpm.setInt(name,value);
  1997.     return 0;
  1998.   } else if (path=="<tmp>") {       // fichier temporaire commun
  1999.     if (tmpf) {
  2000.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2001.     }
  2002.   } else {
  2003.     FILE* fp = fopen(path,"ab");
  2004.     if (fp) {
  2005.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2006.       /*
  2007.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2008.       */
  2009.       fclose(fp);
  2010.       return r;
  2011.     }
  2012.   }
  2013.   return 0;
  2014. }
  2015. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2016.   if (fp) {
  2017.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2018.   }
  2019.   return 0;
  2020. }
  2021. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2022.   if (path.IsEmpty()) {
  2023.     CWinApp* pApp = AfxGetApp();
  2024.     char *tempo;
  2025.     tempo=(char*) malloc(strlen(value)+1);
  2026.     if (tempo) {
  2027.       strcpybuff(tempo,value);
  2028.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2029.     } else
  2030.       return -1;      // error
  2031.   } else if (path=="<mem>") {       // buffer
  2032.     tmpm.setString(name,value);
  2033.     return 0;
  2034.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2035.     if (tmpf) {
  2036.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2037.     }
  2038.   } else {
  2039.     FILE* fp = fopen(path,"ab");
  2040.     if (fp) {
  2041.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2042.       /*
  2043.       char *tempo;
  2044.       tempo=(char*) malloc(strlen(value)+1);
  2045.       if (tempo) {
  2046.       strcpybuff(tempo,value);
  2047.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2048.       fclose(fp);
  2049.       free(tempo);
  2050.       } else
  2051.       return -1;      // error
  2052.       */
  2053.       fclose(fp);
  2054.       return r;
  2055.     }
  2056.   }
  2057.   return 0;
  2058. }
  2059. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2060.   if (fp) {
  2061.     char *tempo;
  2062.     tempo=(char*) malloc(strlen(value)+1);
  2063.     if (tempo) {
  2064.       strcpybuff(tempo,value);
  2065.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2066.       free(tempo);
  2067.     } else
  2068.       return -1;      // error
  2069.   }
  2070.   return 0;
  2071. }
  2072. //
  2073. // lecture
  2074. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2075.   if (path.IsEmpty()) {
  2076.     CWinApp* pApp = AfxGetApp();
  2077.     return pApp->GetProfileInt(dummy,name,value);
  2078.   } else if (path=="<mem>") {       // buffer
  2079.     return tmpm.getInt(name,value);
  2080.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2081.     if (tmpf) {
  2082.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2083.     } else return value;
  2084.   } else {
  2085.     FILE* fp = fopen(path,"rb");
  2086.     if (fp) {
  2087.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2088.       /*
  2089.       char srch[256];
  2090.       sprintf(srch,"%s=",name);
  2091.       while(!feof(fp)) {
  2092.       char s[HTS_URLMAXSIZE*2];
  2093.       linput(fp,s,1020);
  2094.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2095.       int val;
  2096.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2097.       return val;
  2098.       else
  2099.       return value;
  2100.       }
  2101.       }
  2102.       fclose(fp);
  2103.       return value;
  2104.       */
  2105.       fclose(fp);
  2106.       return r;
  2107.     } else return value;
  2108.   }
  2109. }
  2110. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2111.   if (fp) {
  2112.     char srch[256];
  2113.     fseek(fp,0,SEEK_SET);
  2114.     sprintf(srch,"%s=",name);
  2115.     while(!feof(fp)) {
  2116.       char s[2048]; s[0]='\0';
  2117.       linput(fp,s,2000);
  2118.       if (strlen(s)==0)     // EOF
  2119.         return value;
  2120.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2121.         int val;
  2122.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2123.           return val;
  2124.         else
  2125.           return value;
  2126.       }
  2127.     }
  2128.     return value;
  2129.   } else return value;
  2130. }
  2131. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2132.   if (path.IsEmpty()) {
  2133.     CWinApp* pApp = AfxGetApp();
  2134.     char tempo[32768];
  2135.     char value_default[32768];
  2136.     strcpybuff(value_default,value);
  2137.     strcpybuff(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2138.     return profile_decode(tempo);
  2139.   } else if (path=="<mem>") {       // buffer
  2140.     return tmpm.getString(name,value);
  2141.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2142.     if (tmpf) {
  2143.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2144.     } else return value;
  2145.   } else {
  2146.     FILE* fp = fopen(path,"rb");
  2147.     if (fp) {
  2148.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2149.       /*
  2150.       char srch[256];
  2151.       sprintf(srch,"%s",name);
  2152.       strcatbuff(srch,"=");
  2153.       while(!feof(fp)) {
  2154.       char s[32768];
  2155.       linput(fp,s,32000);
  2156.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2157.       return profile_decode(s+strlen(srch));
  2158.       }
  2159.       }
  2160.       fclose(fp);
  2161.       return value;
  2162.       */
  2163.       fclose(fp);
  2164.       return st;
  2165.     } else return value;
  2166.   }
  2167. }
  2168. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2169.   if (fp) {
  2170.     char srch[256];
  2171.     fseek(fp,0,SEEK_SET);
  2172.     sprintf(srch,"%s",name);
  2173.     strcatbuff(srch,"=");
  2174.     while(!feof(fp)) {
  2175.       char s[32768]; s[0]='\0';
  2176.       linput(fp,s,32000);
  2177.       if (strlen(s)==0)     // EOF
  2178.         return value;
  2179.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2180.         return profile_decode(s+strlen(srch));
  2181.       }
  2182.     }
  2183.     return value;
  2184.   } else return value;
  2185. }
  2186.  
  2187. //
  2188. // Get_profile et Write_profile eux mΩmes
  2189. //
  2190. // path="" -> Θcrire dans la base (default)
  2191. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2192. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2193. // path="<null>" -> lire default (illΘgal en Θcriture)
  2194. void Write_profile(CString path,int load_path) {
  2195.   CWaitCursor wait;
  2196.   CString strSection       = "OptionsValues";
  2197.   CString st;
  2198.   int n;
  2199.   
  2200.   // Fichier tempo ou fichier?
  2201.   if (path=="<tmp>") {     // fichier temporaire
  2202.     if (tmpf)
  2203.       fclose(tmpf);
  2204.     tmpf=tmpfile();
  2205.     if (!tmpf)
  2206.       return;
  2207.   } else if (path=="<mem>") {     // buffer temporaire
  2208.     tmpm.deleteAll();
  2209.   } else if (!(path.IsEmpty())) {
  2210.     FILE *fp=fopen(path,"wb");
  2211.     if (fp) 
  2212.       fclose(fp);
  2213.   }
  2214.   
  2215.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2216.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2217.     // checkboxes
  2218.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2219.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2220.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2221.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2222.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2223.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2224.     MyWriteProfileInt(path,strSection, "Dos",
  2225.       ((maintab->m_option2.m_dos)?1:0)
  2226.       +
  2227.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2228.       );
  2229.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2230.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2231.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2232.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2233.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2234.     MyWriteProfileInt(path,strSection, "KeepAlive",maintab->m_option4.m_ka);
  2235.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2236.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2237.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2238.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2239.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2240.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2241.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2242.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2243.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2244.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2245.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2246.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2247.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2248.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2249.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2250.     
  2251.     // menus
  2252.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2253.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2254.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2255.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2256.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2257.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2258.     
  2259.     // champs
  2260.     MyWriteProfileString(path,strSection, "Category", this_CSplitterFrame->GetCurrentCategory());
  2261.  
  2262.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2263.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2264.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2265.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2266.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2267.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2268.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2269.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2270.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2271.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2272.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2273.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2274.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2275.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2276.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2277.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2278.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2279.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2280.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2281.     
  2282.     // 11
  2283.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2284.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2285.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2286.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2287.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2288.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2289.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2290.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2291.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2292.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2293.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2294.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2295.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2296.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2297.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2298.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);
  2299.   } else {
  2300.     st = this_CSplitterFrame->GetCurrentCategory(); MyWriteProfileString(path,strSection,"Category",st);
  2301.  
  2302.     // checkboxes
  2303.     // 1
  2304.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2305.     MyWriteProfileInt(path,strSection,"Near", n);
  2306.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2307.     MyWriteProfileInt(path,strSection,"Test", n);
  2308.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2309.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2310.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2311.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2312.     // 2
  2313.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2314.     MyWriteProfileInt(path,strSection,"Cache", n);
  2315.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2316.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2317.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2318.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2319.     MyWriteProfileInt(path,strSection,"Dos", n);
  2320.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2321.     MyWriteProfileInt(path,strSection,"Index", n);
  2322.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2323.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2324.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2325.     MyWriteProfileInt(path,strSection,"Log", n);
  2326.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2327.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2328.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2329.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2330.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2331.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2332.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2333.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2334.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2335.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2336.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2337.       MyWriteProfileInt(path,strSection, "Build", n);
  2338.     st = maintab->m_option2.Bopt.m_BuildString;
  2339.     if (st.GetLength()>0)
  2340.       MyWriteProfileString(path,strSection, "BuildString",st);
  2341.     // 3
  2342.     // menus
  2343.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2344.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2345.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2346.       MyWriteProfileInt(path,strSection, "Travel", n);
  2347.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2348.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2349.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2350.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2351.     //
  2352.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2353.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2354.     // 4
  2355.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2356.     MyWriteProfileString(path,strSection, "Sockets", st);
  2357.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2358.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2359.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2360.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2361.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2362.     MyWriteProfileString(path,strSection, "Retry", st);
  2363.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2364.     MyWriteProfileString(path,strSection, "RateOut", st);
  2365.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2366.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2367.     n=maintab->m_option4.IsDlgButtonChecked(IDC_ka);
  2368.     MyWriteProfileInt(path,strSection,"KeepAlive", n);
  2369.     // 5
  2370.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2371.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2372.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2373.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2374.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2375.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2376.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2377.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2378.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2379.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2380.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2381.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2382.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2383.     MyWriteProfileString(path,strSection,"Depth",st);
  2384.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2385.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2386.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2387.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2388.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2389.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2390.     // 6
  2391.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2392.     MyWriteProfileString(path,strSection, "UserID", st);
  2393.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2394.     MyWriteProfileString(path,strSection, "Footer", st);
  2395.     // 7
  2396.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2397.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2398.     // 8
  2399.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2400.     MyWriteProfileString(path,strSection, "Cookies", st);
  2401.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2402.     MyWriteProfileString(path,strSection, "CheckType", st);
  2403.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2404.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2405.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2406.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2407.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2408.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2409.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2410.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2411.     // 9
  2412.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2413.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2414.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2415.     MyWriteProfileString(path,strSection, "LogType", st);
  2416.     // 10
  2417.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2418.     MyWriteProfileString(path,strSection,"Proxy",st);
  2419.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2420.     MyWriteProfileString(path,strSection,"Port",st);
  2421.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2422.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2423.     
  2424.     // 11
  2425.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2426.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2427.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2428.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2429.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2430.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2431.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2432.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2433.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2434.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2435.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2436.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2437.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2438.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2439.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2440.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2441.   }
  2442.   // liens, jokers etc. si mirror merge
  2443.   if (!(path.IsEmpty())) {
  2444.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2445.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2446.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2447.       if (dialog1->m_todo >= 0)
  2448.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2449.       //
  2450.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2451.       
  2452.       //if (load_path) {
  2453.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2454.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2455.       //}
  2456.     } else {
  2457.       //dialog1->GetDlgItemText(IDC_depth,st);
  2458.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2459.       dialog1->GetDlgItemText(IDC_URL,st);
  2460.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2461.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2462.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2463.       //
  2464.       dialog1->GetDlgItemText(IDC_filelist,st);
  2465.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2466.       //
  2467.       //if (load_path) {
  2468.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2469.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2470.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2471.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2472.       //}
  2473.     }
  2474.   }
  2475. }
  2476. // path="" -> lire dans la base (default)
  2477. //if not exist: do not load anything but patches projname&co
  2478. void Read_profile(CString path,int load_path) {
  2479.   CWaitCursor wait;
  2480.   CString strSection       = "OptionsValues";
  2481.   CString st;
  2482.   
  2483.   // VΘrification <tmp>
  2484.   if (path=="<tmp>") {     // fichier temporaire
  2485.     if (!tmpf)
  2486.       return;
  2487.     else
  2488.       fflush(tmpf);
  2489.   } else if (path=="<null>") {     // options par dΘfaut
  2490.     path="<mem>";
  2491.     tmpm.deleteAll();              // effacer
  2492.   } else {
  2493.     int pos=path.ReverseFind('\\');
  2494.     if (pos>=0) {
  2495.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2496.       pos=dir.ReverseFind('\\');
  2497.       if (pos>=0) {
  2498.         dir=dir.Left(pos);                  // enlever hts-cache
  2499.         pos=dir.ReverseFind('\\');
  2500.         if (pos>=0) {
  2501.           dialog0->m_projname=dir.Mid(pos+1);
  2502.           dialog0->m_projpath=dir.Left(pos);
  2503.           /*
  2504.           if (this_CWizTab)
  2505.           this_CWizTab->SetActivePage(2);     // page 3
  2506.           */
  2507.         }
  2508.       }
  2509.     }
  2510.   }
  2511.   
  2512.   // checkboxes
  2513.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2514.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2515.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2516.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2517.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2518.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2519.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2520.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2521.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2522.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2523.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2524.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2525.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2526.   maintab->m_option4.m_ka        = MyGetProfileInt(path,strSection, "KeepAlive",1);
  2527.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2528.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2529.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2530.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2531.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2532.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2533.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2534.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2535.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2536.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2537.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2538.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2539.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2540.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2541.   
  2542.   // menus
  2543.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2544.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2545.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2546.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2547.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2548.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2549.   
  2550.   // champs
  2551.   dialog0->m_projcateg =          MyGetProfileString(path,strSection, "Category");
  2552.  
  2553.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2554.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2555.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2556.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2557.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2558.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2559.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2560.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2561.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2562.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2563.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2564.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate", "25000");
  2565.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2566.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2567.   
  2568.   // 7
  2569.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2570.   
  2571.   // 10
  2572.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2573.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2574.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2575.   //
  2576.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2577.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2578.   
  2579.   // 11
  2580.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm,nsf");
  2581.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2582.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2583.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2584.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2585.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2586.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2587.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2588.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2589.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2590.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2591.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2592.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2593.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2594.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2595.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2596.   
  2597.   
  2598.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2599.   //ShellOptions->buff_filtres = st;
  2600.   
  2601.   // liens, jokers etc. si mirror merge
  2602.   if (!(path.IsEmpty())) {
  2603.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2604.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2605.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2606.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2607.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2608.       /*
  2609.       if (load_path) {
  2610.       CString st;
  2611.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2612.       if (st != "")
  2613.       dialog1->m_pathlog = st;
  2614.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2615.       if (st != "")
  2616.       dialog1->m_pathmir = st;
  2617.       }
  2618.       */
  2619.     } else {
  2620.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2621.       //dialog1->SetDlgItemText(IDC_depth,st);
  2622.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2623.       SetDlgItemTextCP(dialog1, IDC_URL,st);
  2624.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2625.       dialog1->m_ctl_todo.SetCurSel(n);
  2626.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2627.       SetDlgItemTextCP(dialog1, IDC_filelist,st);
  2628.       /*
  2629.       if (load_path) {
  2630.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2631.       if (st != "")
  2632.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2633.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2634.       if (st != "")
  2635.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2636.       }
  2637.       */
  2638.       dialog1->Refresh();
  2639.     }
  2640.   }
  2641.   
  2642. }
  2643.  
  2644. // Initialisation du RAS
  2645. void InitRAS() {
  2646. #if USE_RAS
  2647.   if (!LibRas) {
  2648.     LibRas=new CDynamicRAS();
  2649.     if (LibRas->IsRASLoaded()) 
  2650.       LibRasUse=1;
  2651.     else
  2652.       LibRasUse=0;
  2653.   }
  2654. #endif
  2655. }
  2656.  
  2657. // Reconstruire index gΘnΘral!
  2658. void Build_TopIndex(BOOL check_empty) {
  2659.   CWaitCursor wait;
  2660.  
  2661.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2662.   {
  2663.     char path[HTS_URLMAXSIZE*2];
  2664.     strcpybuff(path,CShellApp_app->end_path);
  2665.  
  2666.     /* Build top index */
  2667.     hts_buildtopindex(NULL,path, "");
  2668.  
  2669.     /* Check empty dirs and build .whtt */
  2670.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2671.     //if (fpo) {
  2672.     {
  2673.       // verif_backblue(opt, path);    // gΘnΘrer gif
  2674.       //
  2675.       // Header
  2676.       //fprintf(fpo,toptemplate_header,
  2677.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2678.       //  );
  2679.       // chargement de la liste
  2680.       WIN32_FIND_DATA find;
  2681.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2682.       if (h != INVALID_HANDLE_VALUE) {
  2683.         CString to_delete="";
  2684.         do {
  2685.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2686.             if (strcmp(find.cFileName,".."))
  2687.               if (strcmp(find.cFileName,"."))
  2688.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2689.                   int r;
  2690.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2691.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2692.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2693.                   } else {      /* non vide */
  2694.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2695.                     strcpybuff(iname,CShellApp_app->end_path);
  2696.                     strcatbuff(iname,find.cFileName);
  2697.                     strcatbuff(iname,"\\");
  2698.                     strcpybuff(iname2,iname);
  2699.                     strcatbuff(iname,"index.html");
  2700.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2701.                     if (fexist(iname)) {
  2702.                       char hname[HTS_URLMAXSIZE*2];
  2703.                       strcpybuff(hname,find.cFileName);
  2704.                       escape_check_url(hname);
  2705.                       // Body
  2706.                       //fprintf(fpo,toptemplate_body,
  2707.                       //  hname,
  2708.                       //  find.cFileName
  2709.                       //  );
  2710.                     }
  2711.                     
  2712.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2713.                       // vΘrifier existence de .whtt
  2714.                       strcpybuff(iname,CShellApp_app->end_path);
  2715.                       strcatbuff(iname,find.cFileName);
  2716.                       strcatbuff(iname,".whtt");
  2717.                       if (!fexist(iname)) {
  2718.                         FILE* fp=fopen(iname,"wb");
  2719.                         if (fp) fclose(fp);
  2720.                       }
  2721.                       
  2722.                     }
  2723.                   }
  2724.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2725.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2726.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2727.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2728.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2729.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2730.                       remove(iname);
  2731.                     }
  2732.                   }
  2733.                 }
  2734.         } while(FindNextFile(h,&find));
  2735.         FindClose(h);
  2736.         if (check_empty) {
  2737.           while(to_delete.GetLength()>0) {
  2738.             int pos=to_delete.Find('\n');
  2739.             if (pos) {
  2740.               CString path=to_delete.Left(pos);
  2741.               to_delete=to_delete.Mid(pos+1);
  2742.               CString str;
  2743.               str.Format(LANG_DELETEEMPTYCONF,path);
  2744.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2745.                 /* Θliminer au besoin le .whtt */
  2746.                 DeleteFile(path+".whtt");
  2747.                 if (!RemoveEmptyDir(path))
  2748.                   AfxMessageBox(LANG_ERRORDEL);
  2749.               }
  2750.             } else
  2751.               to_delete="";
  2752.           }
  2753.         }
  2754.       }
  2755.       // Footer
  2756.       //fprintf(fpo,toptemplate_footer,
  2757.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2758.       //  );
  2759.       //fclose(fpo);
  2760.     }
  2761.     
  2762.   }
  2763.  
  2764.   /*
  2765.   if (toptemplate_header)
  2766.     freet(toptemplate_header);
  2767.   if (toptemplate_body)
  2768.     freet(toptemplate_body);
  2769.   if (toptemplate_footer)
  2770.     freet(toptemplate_footer);
  2771.   */
  2772. }
  2773.  
  2774. /*
  2775. -1 : error
  2776. 0 : directory is empty
  2777. 1 : empty directories inside
  2778. 2 : empty files inside
  2779. 3 : 1 + 2
  2780. 4 : not empty
  2781. */
  2782. int CheckDirInfo(CString path) {
  2783.   CWaitCursor wait;
  2784.   
  2785.   if (path.Right(1)!="\\")
  2786.     path+="\\";
  2787.   
  2788.   // Pour FindFirstFile/FindNextFile
  2789.   WIN32_FIND_DATA find;
  2790.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2791.   
  2792.   // accessible
  2793.   if (h!=INVALID_HANDLE_VALUE) {
  2794.     int return_code=0;
  2795.     do {
  2796.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2797.         if (strcmp(find.cFileName,"..")) {
  2798.           if (strcmp(find.cFileName,".")) {
  2799.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2800.               return_code|=1;
  2801.               int r=CheckDirInfo(path+find.cFileName);
  2802.               if (r==4)
  2803.                 return_code=4;
  2804.               else
  2805.                 return_code|=r;
  2806.             } else {
  2807.               return_code|=2;
  2808.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2809.                 return_code=4;
  2810.             }
  2811.           }
  2812.         }
  2813.       }
  2814.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2815.     FindClose(h);
  2816.     return return_code;
  2817.   } else
  2818.     return -1;
  2819. }
  2820.  
  2821. /*
  2822. Remove Empty Dir
  2823. */
  2824. BOOL RemoveEmptyDir(CString path) {
  2825.   CWaitCursor wait;
  2826.   
  2827.   SetCurrentDirectory("C:\\");
  2828.   
  2829.   if (path.Right(1)!="\\")
  2830.     path+="\\";
  2831.   
  2832.   // Pour FindFirstFile/FindNextFile
  2833.   WIN32_FIND_DATA find;
  2834.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2835.   
  2836.   // accessible
  2837.   if (h!=INVALID_HANDLE_VALUE) {
  2838.     do {
  2839.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2840.         if (strcmp(find.cFileName,"..")) {
  2841.           if (strcmp(find.cFileName,".")) {
  2842.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2843.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2844.                 FindClose(h);
  2845.                 return 0;
  2846.               }
  2847.             } else {
  2848.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2849.                 if (!DeleteFile(path+find.cFileName)) {
  2850.                   FindClose(h);
  2851.                   return 0;
  2852.                 }
  2853.             }
  2854.           }
  2855.         }
  2856.       }
  2857.     } while(FindNextFile(h,&find));
  2858.     FindClose(h);
  2859.     
  2860.     SetCurrentDirectory("C:\\");
  2861.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2862.   } else
  2863.     return 0;
  2864.   return TRUE;
  2865. }
  2866.